import { createApp } from 'vue'
// import './style.css'
import '@/theme/index.scss';
import App from './App.vue'
import { router } from '@/router/index';

import store from '@/store/index';
import zhCn from 'element-plus/dist/locale/zh-cn.mjs';// 中文配置
import 'element-plus/theme-chalk/index.css';
import * as ElementPlusIconsVue from '@element-plus/icons-vue'; // 图标
import ElementPlus from 'element-plus';

// 字体
// import '@/assets/font/font.css';
// 图标
// import '@/assets/iconfont/iconfont.css';
// import '@/assets/iconfont/iconfont.js';

// ========================= 富文本编辑器 =========================
import EditorMarkdown from '@/components/article/editor-mark-down.vue';
// ========================= 富文本预览 =========================
import PerviewMarkdown from '@/components/article/preview-mark-down.vue';

/**
 * 初始化vue 
 * 
*/
const app = createApp(App);
app.use(ElementPlus, {
    locale: zhCn
});

// 全局缓存器
app.use(store);

// 解决刷新后 白屏问题
// 动态添加路由需要在main.ts里面也调用一次
import { menuStore } from '@/store/system/menu';
const addDynamicRoute = async () => {
    await menuStore().getDynamicRoute(router);
};
addDynamicRoute();

// 路由
app.use(router);

// 全局指令-权限验证
import directive from "@/utils/directives/index";
directive(app);

// 编辑器
app.component('EditorMarkdown',EditorMarkdown);
app.component('PerviewMarkdown',PerviewMarkdown);

app.mount('#app');

// 全局注册element plus图标
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
    app.component(key, component)
};
